/* 
 *  <copyright file="ConstantRotation.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Text;

using SobrietyEngine.Common;
using Microsoft.Xna.Framework;

namespace SobrietyEngine.Components.Rotation
{
    class ConstantRotation:RotationCmp, SobrietyEngine.Components.IComponent
    {
        float rotBy = 0.0f;
        float PerMs = 100.0f;
        float next = 0.0f;

        public ConstantRotation()
            : base()
        {
        }

        override public void Set(Parameters parms)
        {
            base.Set(parms);
            if (parms.ContainsKey("RotateBy"))
                rotBy = (float)parms["RotateBy"];
            if (parms.ContainsKey("PerMs"))
                PerMs = (float)parms["PerMs"];
            next = PerMs;
        }

        public new void Update(GameTime elapsedTime)
        {
            next -= elapsedTime.ElapsedGameTime.Milliseconds;
            if (next < 0.0f)
            {
                next += PerMs;
                this.RotateBy(rotBy);
            }            
        }
    }
}